package com.cz.nongyetongv5.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.cz.nongyetongv5.R;
import com.cz.nongyetongv5.bean.AssistList;
import com.cz.nongyetongv5.bean.User;
import com.cz.nongyetongv5.decoration.SpacesItemDecoration;
import java.util.ArrayList;
import java.util.List;

public class AssistCollectActivity extends Activity implements View.OnClickListener {
    private User user;
    private RelativeLayout rl_back;
    private RecyclerView recyclerView;
    private List<AssistList> assistLists;
    private View notDataView;
    private AssistAdapter adapter;


    private LinearLayout ll_ent_collect;
    private LinearLayout ll_patrol_collect;
    private LinearLayout ll_supervise_collect;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_assist_collect);
        user = (User) getIntent().getSerializableExtra("user");
        rl_back = findViewById(R.id.rl_back);
        rl_back.setOnClickListener(this);
        recyclerView = findViewById(R.id.recyclerView);
        assistLists = new ArrayList<>();
//        assistLists.add(new AssistList(R.drawable.ic_ent_check, "主体信息审核"));
//        assistLists.add(new AssistList(R.drawable.ic_supervise_check, "监管对象更新审核"));
        assistLists.add(new AssistList(R.drawable.ic_ent_manager, "主体信息维护"));
        assistLists.add(new AssistList(R.drawable.ic_assist_patrol, "日常巡查"));
        assistLists.add(new AssistList(R.drawable.ic_supervise_manager, "调查对象管理"));
        adapter = new AssistAdapter();
        notDataView = getLayoutInflater().inflate(R.layout.view_nodata, (ViewGroup) recyclerView.getParent(), false);
        recyclerView.setLayoutManager(new GridLayoutManager(AssistCollectActivity.this, 3, GridLayoutManager.VERTICAL, false));
        adapter.setEmptyView(notDataView);
//        recyclerView.setAdapter(adapter);
        //添加ItemDecoration，item之间的间隔
        int leftRight = dip2px(25);
        int topBottom = dip2px(20);
        recyclerView.addItemDecoration(new SpacesItemDecoration(leftRight, topBottom));
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
//                if (position == 0) {//主体信息审核
//                    Intent intent = new Intent(AssistCollectActivity.this, AssistEntCheckActivity.class);
//                    intent.putExtra("user", user);
//                    startActivity(intent);
//                } else if (position == 1) {//监管对象更新审核
//                    Intent intent = new Intent(AssistCollectActivity.this, AssistSuperviseCheckActivity.class);
//                    intent.putExtra("user", user);
//                    startActivity(intent);
//                } else if (position == 2) {//主体信息维护
//                    Intent intent = new Intent(AssistCollectActivity.this, AssistEntUpdateActivity.class);
//                    intent.putExtra("user", user);
//                    startActivity(intent);
//                } else if (position == 3) {//日常巡查
//                    Intent intent = new Intent(AssistCollectActivity.this, AssistPatrolActivity.class);
//                    intent.putExtra("user", user);
//                    startActivity(intent);
//                } else if (position == 4) {//监管对象监管
//                    Intent intent = new Intent(AssistCollectActivity.this, AssistSuperviseActivity.class);
//                    intent.putExtra("user", user);
//                    startActivity(intent);
//                }
                if (position == 0) {//主体信息维护
                    Intent intent = new Intent(AssistCollectActivity.this, AssistEntUpdateActivity.class);
                    intent.putExtra("user", user);
                    startActivity(intent);
                } else if (position == 1) {//日常巡查
                    Intent intent = new Intent(AssistCollectActivity.this, AssistPatrolActivity.class);
                    intent.putExtra("user", user);
                    startActivity(intent);
                } else if (position == 2) {//监管对象监管
                    Intent intent = new Intent(AssistCollectActivity.this, AssistSuperviseActivity.class);
                    intent.putExtra("user", user);
                    startActivity(intent);
                }
            }
        });

        ll_ent_collect=findViewById(R.id.ll_ent_collect);
        ll_patrol_collect=findViewById(R.id.ll_patrol_collect);
        ll_supervise_collect=findViewById(R.id.ll_supervise_collect);
        ll_ent_collect.setOnClickListener(this);
        ll_patrol_collect.setOnClickListener(this);
        ll_supervise_collect.setOnClickListener(this);

    }

    public int dip2px(float dpValue) {
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpValue, getResources().getDisplayMetrics());
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rl_back:
                finish();
                break;
            case R.id.ll_ent_collect:
                Intent entIntent = new Intent(AssistCollectActivity.this, AssistEntUpdateActivity.class);
                entIntent.putExtra("user", user);
                startActivity(entIntent);
                break;
            case R.id.ll_patrol_collect:
                Intent patrolIntent = new Intent(AssistCollectActivity.this, AssistPatrolActivity.class);
                patrolIntent.putExtra("user", user);
                startActivity(patrolIntent);
                break;
            case R.id.ll_supervise_collect:
                Intent superviseIntent = new Intent(AssistCollectActivity.this, AssistSuperviseActivity.class);
                superviseIntent.putExtra("user", user);
                startActivity(superviseIntent);
                break;
            default:
                break;
        }
    }

    public class AssistAdapter extends BaseQuickAdapter<AssistList, BaseViewHolder> {
        public AssistAdapter() {
            super(R.layout.assist_collect_item, assistLists);
        }

        @Override
        protected void convert(BaseViewHolder viewHolder, AssistList item) {
            Glide.with(mContext)
                    .load(item.getResId())
                    .into((ImageView) viewHolder.getView(R.id.iv_iv));
            viewHolder.setText(R.id.tv_name, item.getName());
        }
    }


}